package com.yugao.fintech.draper.admin.controller;

import com.yugao.fintech.draper.admin.service.TenantPackageService;
import com.yugao.fintech.draper.auth.dto.TenantPackageDTO;
import com.yugao.fintech.draper.datasource.entity.PageResult;
import com.yugao.fintech.draper.admin.param.TenantPackageQuery;
import com.yugao.fintech.draper.core.model.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tenant/package")
@RequiredArgsConstructor
@Tag(name = "租户套餐管理")
public class TenantPackageController {

	private final TenantPackageService tenantPackageService;

	@Operation(summary = "查询租户套餐信息分页列表")
	@GetMapping(value = "/page")
	public ResultVO<PageResult<TenantPackageDTO>> pageQuery(@RequestBody TenantPackageQuery tenantPackageQuery) {
		return ResultVO.success(PageResult.success(tenantPackageService.pageQuery(tenantPackageQuery)));
	}

	@Operation(summary = "保存租户套餐信息")
	@PostMapping(value = "/add")
	public ResultVO<Boolean> add(@RequestBody TenantPackageDTO tenantPackageDTO) {
		return ResultVO.success(tenantPackageService.addTenantPackage(tenantPackageDTO));
	}

	@Operation(summary = "更新租户套餐信息")
	@PostMapping(value = "/update")
	public ResultVO<Boolean> update(@RequestBody TenantPackageDTO tenantPackageDTO) {
		return ResultVO.success(tenantPackageService.updateTenantPackage(tenantPackageDTO));
	}

	@Operation(summary = "删除租户套餐信息")
	@DeleteMapping(value = "/delete")
	public ResultVO<Boolean> delete(Long id) {
		return ResultVO.success(tenantPackageService.deleteByTenantPackageId(id));
	}

	@Operation(summary = "获取租户套餐信息")
	@GetMapping(value = "/findById")
	public ResultVO<TenantPackageDTO> findById(Long id) {
		return ResultVO.success(tenantPackageService.findById(id));
	}

	@Operation(summary = "获取全部租户套餐信息")
	@GetMapping(value = "/findAll")
	public ResultVO<List<TenantPackageDTO>> findAll() {
		return ResultVO.success(tenantPackageService.findAll());
	}
}